//
// Created by Asus on 2025/6/1.
//

#include <iostream>
using namespace std;

//类模板
template<class NameType, class AgeType = int>
class Person {
public:
    Person(NameType name, AgeType age) {
        this->mName = name;
        this->mAge = age;
    }

    void showPerson() {
        cout << "name: " << this->mName << " age: " << this->mAge << endl;
    }

public:
    NameType mName;
    AgeType mAge;
};

//1、指定传入的类型
void printPerson1(Person<string, int> &p) {
    p.showPerson();
}

//2、参数模板化
template<class T1, class T2>
void printPerson2(Person<T1, T2> &p) {
    p.showPerson();
}

//3、整个类模板化
template<class T>
void printPerson3(T &p) {
    cout << "T的类型为：" << typeid(T).name() << endl;
    p.showPerson();
}

void demo01() {
    Person <string, int >p("孙悟空", 100);
    printPerson1(p);

    Person <string, int >p2("猪八戒", 90);
    printPerson2(p2);

    Person <string, int >p3("唐僧", 30);
    printPerson3(p);
}


int main(int argc, char *argv[]) {
    demo01();
    return 0;
}
